package com.lsa.letcode.the9.palindrome;

public class Solution {
	public boolean isPalindrome(int x) {
		if (x < 0) {
			return false;
		}
		if (x < 10) {
			return true;
		}
		int leftFactor = 10;
        while(x / leftFactor >= 10) {
        	leftFactor *= 10;
        }
        
    	while(x != 0) {
    		int leftDigit = x / leftFactor;
    		int rightDigit = x % 10;
    		
    		if (leftDigit != rightDigit) {
    			return false;
    		}
    		
    		// 12345 -> 234 -> 3
    		// 1234567 -> 23456 -> 345 -> 4
    		x = (x % leftFactor) / 10;
    		leftFactor /= 100;
    	}
		return true;
	}
}
